#Copyright (c) 2025, Alibaba Cloud and its affiliates;
#Licensed under the Apache License, Version 2.0 (the "License");
#you may not use this file except in compliance with the License.
#You may obtain a copy of the License at

#   http://www.apache.org/licenses/LICENSE-2.0

#Unless required by applicable law or agreed to in writing, software
#distributed under the License is distributed on an "AS IS" BASIS,
#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#See the License for the specific language governing permissions and
#limitations under the License.



# coding=utf-8
import os
import json


def init_default_config():
    conf = dict(jwt_secret_key="AliFCE*@123",
                is_debug=True,
                jwt_release_time=60 * 30,
                jwt_expire_time=60 * 60,
                serv_name=os.getenv('SERV_NAME', 'FCESERVER'),
                fce_util='/usr/local/fce/bin/fceutil',
                access_log_file='logs/web.log',
                access_log_format='%(asctime)s - %(cluster)s - %(filename)s - %(levelname)s\
                            - Line %(lineno)s: %(message)s',
                operate_log_file='logs/operate/operate.log',
                operate_log_format='%(message)s')
    conf['client_config'] = os.getcwd() + '/' + 'config/client_config.json'

    # 操作日志记录的范围，路由
    conf['operates'] = [
        'listRayClusters', 'createRayCluster', 'deleteRayCluster'
    ]

    # db
    conf['db_local_file'] = os.getcwd() + '/' + 'sqlite.db'
    return conf


def get_config():
    conf = init_default_config()
    return conf


def get_application_path():
    conf = init_default_config()
    return conf['application_path']


def read_client_config():
    conf = init_default_config()
    return json.loads(open(conf['client_config']).read())


def read_server_version():
    conf = init_default_config()
    return open(conf['server_version']).read()


def read_common_params(language='zh-cn'):
    conf = init_default_config()
    if language == 'zh-cn':
        return json.loads(open(conf['params_zh']).read())
    else:
        return json.loads(open(conf['params_en']).read())

